from rest_framework.serializers import ModelSerializer
from course import models


# 定义一个序列化器类
class CateSer(ModelSerializer):
    class Meta:
        model = models.CateModel
        fields = ['id', 'name']


class CategorySer(ModelSerializer):
    son = CateSer(many=True)

    class Meta:
        model = models.CateModel
        fields = ['id', 'name', 'son']


class TeacherSer(ModelSerializer):
    class Meta:
        model = models.TeacherModel
        fields = ['name', 'image', 'jobtitle']


class CourseSer(ModelSerializer):
    teacher = TeacherSer()

    class Meta:
        model = models.CourseModel
        fields = '__all__'
